	import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
	
public class Filmwahl extends JFrame {

	    private JPanel jPanel1 = new JPanel(null, true);
	    private JLabel jLabel2 = new JLabel();
	    private JPanel jPanel2 = new JPanel(null, true);
	    private JPanel jPanel4 = new JPanel(null, true);
	    private JButton jStornieren = new JButton("Weiter zur Platzwahl");
	    private JLabel jLabel1 = new JLabel();
	    private JPanel jPanel3 = new JPanel(null, true);
	    private JTable jTable1 = new JTable(100, 4);
	    private DefaultTableModel jTable1Model = (DefaultTableModel) jTable1.getModel();
	    private JScrollPane jTable1ScrollPane = new JScrollPane(jTable1);
	    Database db;
	    User user;
	
	public Filmwahl(Database db, User userObj) throws SQLException {
	    super("Filmwahl");
	    this.user=userObj;
	    this.db=db;
	  //  setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	    int frameWidth = 779; 
	    int frameHeight = 384;
	    setSize(frameWidth, frameHeight);
	    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
	    int x = (d.width - getSize().width) / 2;
	    int y = (d.height - getSize().height) / 2;
	    setLocation(x, y);
	    setResizable(false);
	    Container cp = getContentPane();
	    cp.setLayout(null);
	    // Anfang Komponenten
	    
	    jPanel1.setBounds(8, 8, 761, 337);
	    jPanel1.setOpaque(false);
	    cp.add(jPanel1);
	    jPanel2.setBounds(8, 48, 761, 297);
	    jPanel2.setOpaque(false);
	    cp.add(jPanel2);
	    jPanel3.setBounds(8, 88, 497, 249);
	    jPanel3.setOpaque(false);
	    cp.add(jPanel3);
	    jPanel4.setBounds(520, 48, 233, 249);
	    jPanel4.setOpaque(false);
	    jPanel2.add(jPanel4);
	    
	    
	    jStornieren.setBounds(50, 120, 150, 35);
	    jStornieren.setMargin(new Insets(2, 2, 2, 2));
	    jStornieren.addActionListener(new ActionListener() { 
	      public void actionPerformed(ActionEvent evt) { 
	        try {
				jStornieren_ActionPerformed(evt);
			} catch (NumberFormatException | SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	      }
	    });
	    
	    jPanel4.add(jStornieren);
	    jPanel4.add(jLabel1);
	    jLabel2.setBounds(288, 0, 164, 35);
	    jLabel2.setText("Filmwahl");
	    jLabel2.setFont(new Font("Arial Narrow", Font.BOLD, 26));
	    jPanel1.add(jLabel2);
	   
	  
	    jTable1ScrollPane.setBounds(16, 16, 457, 233);
	    jTable1.getColumnModel().getColumn(0).setHeaderValue("Nr.");
	    jTable1.getColumnModel().getColumn(1).setHeaderValue("Film");
	    jTable1.getColumnModel().getColumn(2).setHeaderValue("Datum");
	    jTable1.getColumnModel().getColumn(3).setHeaderValue("Zeit");
	    
	    ResultSet rs = db.getData("SELECT VeranstaltungsID,FilmID,Datum,Zeit FROM veranstaltungen");
	    
	    int row=0;
	    	    
	    while(rs.next()){
	    	    jTable1.setValueAt(rs.getString(1),row,0);
	    	    ResultSet rsFilm = db.getData("SELECT Filmtitel FROM filme WHERE Filmnummer = " + Integer.parseInt(rs.getString(2)));
	    	    rsFilm.next();
	    	    jTable1.setValueAt(rsFilm.getString(1),row,1);
	    	    jTable1.setValueAt(rs.getString(3),row,2);
	    	    jTable1.setValueAt(rs.getString(4),row,3);
	    	    System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4));
	    	    row++;
	  }
	    
	    jPanel3.add(jTable1ScrollPane);
	    // Ende Komponenten
	    
	    setVisible(true);
	  } // end of public resverw
	  
	  // Anfang Methoden
	  public void jStornieren_ActionPerformed(ActionEvent evt) throws NumberFormatException, SQLException {
		  int temp = Integer.parseInt((String) jTable1.getValueAt(jTable1.getSelectedRow(),0));
		  System.out.println("ID der Veranstaltung ist: " + temp);
		  Vorfuehrung vfr = new ConvertTo().vorfuehrung(db, temp);
		  dispose();
          new TakeASeat(db,vfr,user);
	  } 
	  
	  
	  
	  public static void main(String[] args) {
	    new resverw("Filmwahl");
	  } // end of main
	  
	} // end of class resverw


